
package com.zsrt.examsystem;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import com.zsrt.examsystem.dao.StudentMethodDao;
import com.zsrt.examsystem.impl.Methods;
import com.zsrt.examsystem.impl.StudentMethodDaoImpl;
import com.zsrt.examsystem.stduententity.Student;


/**
 * 固定的一些信息
 * @author jmj
 * @date 2017年4月23日
 * @time 下午4:05:05
 */
public class MethodUtil {

	private static List<Student> students = MethodUtil.studentMessage();
	private static Methods methods = new Methods();
	
	/**
	 * 管理员登录以及选择
	 * @param scanner
	 */
	public static void adminLoginPage(Scanner scanner) {
		File file = new File("src/com/zsrt/book/user.properties");
		System.out.println("请输入管理员账户");
		String name = scanner.next();
		
		System.out.println("请输入管理员密码");
		String password = scanner.next();
		if(name.equals("admin") && password.equals("admin")){
		
			System.err.println("登陆成功");
			secondAdminPage();
			int num1 = scanner.nextInt();
			while(true){
				
				if(num1==1){
					//操作数为1  录入考生信息
					methods.addStuInformathion();
					
				}else if(num1==2){
					//操作数为2 修改考生信息   
					//输入你想修改的信息
					Student student=MethodUtil.printStudent(scanner);
					methods.updateStuInformation(students, student);
					
				}else if(num1 ==3){
					//操作数为3  删除考生信息   
					//输入你想修改的信息
					Student student=MethodUtil.printStudent(scanner);
					
					methods.deleteStuInformation(students, student);
				}else if(num1==4){
					//操作数为4  查询考生信息   
					MethodUtil.queryStudentMenu();
					int num2 = scanner.nextInt();
					
					if(num2==1){
						//操作数为1  打印所有考生信息
						methods.printAllStudent(students );
						
					}else if(num2==2){
						// 操作数为2  根据户籍查询考生信息     
						System.out.println("请输入该考生的户籍");
						String orderHuji = scanner.next();
						methods.printStudentByHuji(students, orderHuji);
						
					}else if(num2==3){
						// 操作数为3  根据姓名查询考生信息  
						System.out.println("请输入该考生的姓名");
						String orderName = scanner.next();
						methods.printStudentByName(students, orderName );
						
					}else if(num2==4){
						// 操作数为4   根据准考证号查询考生信息
						System.out.println("请输入该考生的准考证号");
						String orderIdExam = scanner.next();
						methods.printStudentByidExam(students, orderIdExam );
					}else {
						//返回上一层
						break;
					}
					
				}
			}
		}else{
			System.out.println("用户名或密码错误,您已被强制退出...");
		}
	}

	/**
	 * 管理员第一界面
	 */
	public static void firstPage() {
		System.err.println("\t\t _____________________________");
		System.err.println("\t\t         欢迎登录高考成绩自主查询系统        ");
		System.err.println("\t\t —————————————————————————————");
		System.err.println("\t\t          1. 管理员登录                 ");
		System.err.println("\t\t          2. 考 生登录              ");
		System.err.println("\t\t          3. 退   出                       ");
		System.err.println("\t\t —————————————————————————————");
		System.err.println("请输入相应的操作数：");

		
	}
	
	/**
	 * 管理员第二界面
	 */
	public static void secondAdminPage(){
		System.err.println("\t\t _____________________________");
		System.err.println("\t\t         欢迎进入管理员主界面        ");
		System.err.println("\t\t —————————————————————————————");
		System.err.println("\t\t          1.录入考生信息                 ");
		System.err.println("\t\t          2.修改考生信息              ");
		System.err.println("\t\t          3.删除考生信息              ");
		System.err.println("\t\t          4.查询考生信息              ");
		System.err.println("\t\t          5.返回上一层                       ");
		System.err.println("\t\t —————————————————————————————");
		System.err.println("请输入相应的操作数:");
	}

	/**
	 * 所有考生的信息
	 * @return
	 */
	public static List<Student> studentMessage(){
		
		
		List<Student> arrays = new ArrayList<Student>();
		Student student1 = new Student("170001","123","贾梦菊","女",22,"安徽省","宿州市","123",110,105,125);
		Student student2 = new Student("170002","123456","罗智壕","男",25,"安徽省","合肥市","15866677151",100,90,135);
		Student student3 = new Student("170003","123456","贾静雯","女",27,"安徽省","芜湖市","15677779999",120,115,130);
		Student student4 = new Student("170004","123456","靳志辉","男",25,"广东省","深圳市","12344445555",90,115,100);
		Student student5 = new Student("170005","123456","段誉","男",23,"广东省","广州市","13566667777",130,95,115);
		Student student6 = new Student("170006","123456","张杰","男",24,"四川省","成都市","18866668888",120,135,95);
		Student student7 = new Student("170007","123456","谢娜","女",21,"四川省","成都市","18672637638",120,85,105);
		
		arrays.add(student1);
		arrays.add(student2);
		arrays.add(student3);
		arrays.add(student4);
		arrays.add(student5);
		arrays.add(student6);
		arrays.add(student7);
		return arrays ;
	}
	
	/**
	 * 学生的添加及打印
	 * @param scanner
	 * @return
	 */
	public static Student printStudent(Scanner scanner){
		
		System.out.println("请输入学生准考证号：");
		String idExam = scanner.next();
		
		System.out.println("请输入学生密码：");
		String password = scanner.next();
		
		System.out.println("请输入学生姓名：");
		String name = scanner.next();
		
		System.out.println("请输入学生性别：");
		String sex = scanner.next();
		
		System.out.println("请输入学生年龄：");
		int age = scanner.nextInt();
		
		System.out.println("请输入学生所属省份：");
		String province = scanner.next();
		
		System.out.println("请输入学生户籍：");
		String huji = scanner.next();
		
		System.out.println("请输入学生联系方式：");
		String phone = scanner.next();
		
		System.out.println("请输入学生语文成绩：");
		int chineseScore = scanner.nextInt();
		
		System.out.println("请输入学生数学成绩：");
		int mathScore = scanner.nextInt();
		
		System.out.println("请输入学生英语成绩：");
		int englishScore = scanner.nextInt();
		Student student=new Student( idExam,  password,  name,  sex,  age,  province,  huji,
			 phone,  chineseScore,  mathScore,  englishScore);
		return student;
	}
	
	/**
	 * 查询考生信息主界面
	 */
	public static void queryStudentMenu(){
		System.err.println("\t\t _____________________________");
		System.err.println("\t\t         欢迎进入查询考生信息主界面        ");
		System.err.println("\t\t —————————————————————————————");
		System.err.println("\t\t          1.显示所有考生信息                 ");
		System.err.println("\t\t          2.根据户籍查询考生信息              ");
		System.err.println("\t\t          3.根据姓名查询考生信息              ");
		System.err.println("\t\t          4.根据准考证号查询考生信息              ");
		System.err.println("\t\t          5. 返回上一层                       ");
		System.err.println("\t\t —————————————————————————————");
		System.err.println("请输入相应的操作数:");
	}

	/**
	 * 考生界面菜单
	 */
	public static  void userFirstMenu(){
		System.err.println("\t\t ___________________________________________________");
		System.err.println("\t\t               欢迎进入考生主界面        ");
		System.err.println("\t\t ————————————————————————————————————————————————————");
		System.err.println("\t\t          1.我的信息                 ");
		System.err.println("\t\t          2.查询本市总分状元              ");
		System.err.println("\t\t          3.查询全国各个省份的状元              ");
		System.err.println("\t\t          4.查询指定城市的状元              ");
		System.err.println("\t\t          5.查询各个省份200-300分的总人数并由高到低排列显示                       ");
		System.err.println("\t\t          6.查询各个省份过300分的总人数并由低到高排列显示                ");
		System.err.println("\t\t          7. 返回上一层                       ");
		System.err.println("\t\t ———————————————————————————————————————————————————");
		System.err.println("请输入相应的操作数:");
	}

	
	/**
	 * 学生登录选择信息
	 * @param scanner
	 * @param students
	 */
	public static void studentLoginPage(Scanner scanner,List<Student> students) {
		
		StudentMethodDao dao=new StudentMethodDaoImpl();
		students = MethodUtil.studentMessage();
		System.out.println("请输入考生手机号");
		String phone = scanner.next();
		
		System.out.println("请输入考生密码");
		String password = scanner.next();
		
		for(int index=0;index<students.size();index++){
			Student student = students.get(index);
			if(phone.equals(student.getPhone()) && password.equals(student.getPassword())){
				
				System.err.println("登陆成功");
				while(true){
					
					MethodUtil.userFirstMenu();
					int num = scanner.nextInt();
					if(num ==1){
						System.out.println("请输入您的名字：");
						String ownName = scanner.next();
						//查看我的信息
						dao.searchPersonalInformation(students, ownName );
						
					}else if(num==2){
						//查询本市总分状元  
						System.out.println("请输入你的户籍即城市：");
						String ownHuji = scanner.next();
						Student student1= dao.checkMaxScoreByHuji(students,ownHuji );
						
						System.out.println(student1);
						
					}else if(num==3){
						//查询全国各个省份的状元 
						List<Student> students2 =dao.checkMaxEveryCity(students);
						for(Student s: students2){
							System.out.println(s);
						}
						
					}else if(num==4){
						//查询指定城市的状元
						System.out.println("请输入您想查询的城市：");
						String  city = scanner.next();
						Student student2 =dao.checkMaxOfCity(city ,students);
						
						System.out.println(student2);
					}else if(num==5){
						// 统计分析报表     查询各个省份200-350分的总人数并由高到低排列显示
						System.out.println("请输入查询的最低的分数");
						int lowScore = scanner.nextInt();
						System.out.println("请输入查询的最高的分数");
						int highScore = scanner.nextInt();
						dao.checkScoreByProvince(students,lowScore,highScore);
						/*Collections.sort(students);
						for(Student s: students){
							System.out.println(s);
						}*/
					}else if(num==6){
						
						System.out.println("请输入不低于多少分");
						int newScore = scanner.nextInt();
						//查询各个省份过300分的总人数并由低到高排列显示
						dao.checkScoreByProvinceAsc(students, newScore );
						
						/*Collections.sort(students, new Comparator<Student>() {
							public int compare(Student o1, Student o2) {
								// 按照客数量进行排序
								int totalScore = o1.getChineseScore()+o1.getEnglishScore()+o1.getMathScore();

								int totalScore1 = o2.getChineseScore()+o2.getEnglishScore()+o2.getMathScore();
								
								if(totalScore1 - totalScore>=0){
									return  1;
								}else{
									return -1;
								}
							}
						});*/
						
					}else{
						//返回上一层
						break;
					}
				}
				
			}else{
				System.err.println("用户名或密码错误...");
				
			}
		}
	}

	
}
